package gui;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JProgressBar;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;

public class ConnectionMenu extends JFrame {

	private static final long serialVersionUID = 1L;

	JButton connectButton;
	JProgressBar progressBar;
	JLabel lblAwaiting;
	String endpoint = "http://localhost:8080/CastleWarServer/services/Game";
	String player;
	JTextField textField;
	JComboBox<String> comboBox;

	public static void main(String[] args) {
		// ustawianie L&F
		try
		{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch(ClassNotFoundException e1)
		{
			e1.printStackTrace();
		}
		catch(InstantiationException e1)
		{
			e1.printStackTrace();
		}
		catch(IllegalAccessException e1)
		{
			e1.printStackTrace();
		}
		catch(UnsupportedLookAndFeelException e1)
		{
			e1.printStackTrace();
		}

		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					ConnectionMenu window = new ConnectionMenu();
					window.setLocationRelativeTo(null);
					window.setVisible(true);

				}

				catch(Exception e)
				{
					e.printStackTrace();
				}
			}
		});
	}

	public ConnectionMenu (){
		setTitle("Castle War Connection Menu");

		init();
	}
	private void init(){
		getContentPane().setLayout(null);
		setBounds(0, 0, 450, 300);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		connectButton = new JButton("Connect");
		connectButton.setBounds(173, 113, 89, 23);
		connectButton.addActionListener(new ConnectionEvents(this));
		getContentPane().add(connectButton);

		progressBar = new JProgressBar();
		progressBar.setIndeterminate(true);
		progressBar.setVisible(false);
		progressBar.setBounds(140, 179, 146, 14);
		getContentPane().add(progressBar);

		lblAwaiting = new JLabel("Awaiting for another player");
		lblAwaiting.setVisible(false);
		lblAwaiting.setBounds(140, 154, 152, 14);
		getContentPane().add(lblAwaiting);

		comboBox = new JComboBox<String>();
		comboBox.setModel(new DefaultComboBoxModel<String>(new String[] {"ORANGE", "BLUE"}));
		comboBox.setBounds(173, 82, 89, 20);
		getContentPane().add(comboBox);

		textField = new JTextField();
		textField.setText(endpoint);
		textField.setBounds(53, 43, 312, 20);
		getContentPane().add(textField);
		textField.setColumns(10);
	}
}
